home *** CD-ROM | disk | FTP | other *** search
- Path: news.dseg.ti.com!news
- From: grubin@ti.com (Geoffrey Rubin)
- Newsgroups: comp.lang.c++
- Subject: Re: [HLP] Easy Problem w/ Classes!
- Date: 22 Feb 1996 18:46:14 GMT
- Organization: AWP
- Message-ID: <4gidlm$fat@mksrv1.dseg.ti.com>
- References: <4gfn3v$jp@news.umbc.edu>
- NNTP-Posting-Host: cna0185662.dseg.ti.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4gfn3v$jp@news.umbc.edu>, ssopre1@umbc.edu says...
- >
- >Hello all
- > Heres a little problem that I need help with.
- >
- >// Point.h contains
- >Class Point {
- >private: int x;
- > int y;
- >
- >public: Point();
- >}
- >
- >// LineSeg.h contains
- >class LineSeg{
- >private:
- > Point end;
- > Point start;
- >public:
- > LineSeg();
- >}
- >
- >// LineSeg.C contains
- >LineSeg::LineSeg()
- >{
- > Point.end.x=0; // Are these valid?
- > Point.end.y=0; // What do I need to add/del here?
- > Point.start.x=0;
- > Point.start.y=0;
- >}
- >
- >Basically, LineSeg() is supposed to set starting and ending
- >points to zero. Compiler goes berserkoid .. .
- Since x and y are private members of Point, you can not access them
- in LineSeg. You can add other versions of your constructor to initialize
- x and y such as:
- Point(int TheX ...)
- and initialize them like:
- Point end(0,0) ; ...
-
- Or you can add other methods to Point to set x and y values
- such as:
- class Point
- {
- ...
- public:
- void SetX(int TheX) ;
- }
-
- and then use them:
-
- end.SetX(0) ;
-
- Or you can make x and y public members (not recommended)
- and do the following in LineSeg:
-
- end.x = 0 ;
- start.y = 0 ;
-
- But you can never do the following!!!:
- Point.end.x=0;
-
- Geoffrey
-
-
-